<template>
	<view>
		<home-page v-if="pageId?true:false" :pageId="pageId" ref="modulePageRef" @changNav="changNav"
			@changTopic="changTopic"></home-page>
		<template v-for="(item,index) in pageIds">
			<view v-show="currentIndex === index" :key="index">
				<home-page :ref="'moduleOther_' + index" :pageId="item" :autoInit="false" :hasTop="hasTop"></home-page>
			</view>
		</template>
		<sww-sidebar :scroll-top="scrollTop" :contact="contact"></sww-sidebar>
		<sww-login></sww-login>
	</view>
</template>

<script>
	import {
		pageShare
	} from '@/mixins/pageShare';
	import {
		commonPage
	} from '@/mixins/commonPage.js'
	import homePage from '@/pagecomponents/homePage/homePage';
	export default {
		mixins: [pageShare, commonPage],
		components: {
			homePage
		},
		data() {
			return {
				pageIds: [],
				currentIndex: 0,
				scrollTop: 0,
				pageId: null,
				title: '',
				contact:false,
				hasTop:false
			};
		},
		onLoad(options) {
			this.pageId = Number(options.id)
			if (options.title) {
				this.title = options.title || ''
				uni.setNavigationBarTitle({
					title: options.title
				});
			}
		},
		onPullDownRefresh() {
			this.pageIds = []
			if (this.$refs.modulePageRef.$onPullDownRefresh) {
				this.$refs.modulePageRef.$onPullDownRefresh();
			}
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 700)
		},
		onReachBottom() {
			let str = 'moduleOther_' + this.currentIndex
			if (!this.pageIds[0] && this.$refs.modulePageRef.$onReachBottom) {
				this.$refs.modulePageRef.$onReachBottom();
			} else if (this.$refs[str][0] && this.$refs[str][0].$onReachBottom) {
				this.$refs[str][0].$onReachBottom();
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 微信小程序分享(好友)
		onShareAppMessage: function() {
			let obj = this.getShareAppMessage()
			return obj
		},
		// 微信小程序分享(朋友圈)
		onShareTimeline: function() {
			return this.getShareTimeline()
		},
		methods: {
			changNav(item) {
				this.contact = item.contact
				this.hasTop = item.hasTop
				uni.setNavigationBarColor({
					frontColor: item.fColor || '#000000',
					backgroundColor: item.bgColor || '#ffffff'
				});
				if (!this.title) {
					uni.setNavigationBarTitle({
						title: item.title
					});
				}
			},
			changTopic(obj) {
				if (obj.arrid) {
					this.pageIds = [].concat(obj.arrid)
				}
				this.currentIndex = obj.index
				this.$nextTick(() => {
					let str = 'moduleOther_' + obj.index
					if (this.$refs[str][0].manualInit) {
						this.$refs[str][0].manualInit();
					}
				})
			},
		}
	};
</script>

<style scoped lang="scss"></style>
